using UnityEngine;

public class DropObject : MonoBehaviour
{
	public GameObject[] Objects;

	public Transform DropLocation;

	public float RandomForce;

	private void Start()
	{
		GameObject[] objects = Objects;
		foreach (GameObject gameObject in objects)
		{
			gameObject.GetComponent<Rigidbody>().maxAngularVelocity = 1000f;
		}
		drop(-1);
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.Q))
		{
			drop(-1);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha1))
		{
			drop(0);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha2))
		{
			drop(1);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha3))
		{
			drop(2);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha4))
		{
			drop(3);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha5))
		{
			drop(4);
		}
	}

	private void drop(int obj)
	{
		for (int i = 0; i < Objects.Length; i++)
		{
			if (obj == -1 || i == obj)
			{
				GameObject gameObject = Objects[i];
				gameObject.transform.position = DropLocation.position + UnityEngine.Random.insideUnitSphere * 1.5f;
				gameObject.GetComponent<Rigidbody>().velocity = new Vector3(UnityEngine.Random.Range(0f - RandomForce, RandomForce), UnityEngine.Random.Range(0f - RandomForce, RandomForce), 0f);
				gameObject.GetComponent<Rigidbody>().angularVelocity = UnityEngine.Random.insideUnitSphere * RandomForce;
			}
		}
	}

	private void OnGUI()
	{
		GUILayout.BeginArea(new Rect(10f, 10f, Screen.width - 20, 50f));
		GUILayout.BeginHorizontal();
		GUILayout.FlexibleSpace();
		GUILayout.Box(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
		GUILayout.Box("Press 'Q' to drop objects.");
		GUILayout.Box("Press '1', '2', '3', '4', or '5' to drop specific objects.");
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.EndArea();
	}
}
